package com.community.service;

import com.community.entity.Order;
import com.feng.fengDUtil.BaseService;
import com.community.util.Search;
import com.feng.fengDUtil.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Map;

@Service
@Transactional
public class OrderService extends BaseService{

    public Page query(Page page, Search search) {
        ArrayList params = new ArrayList();
        String sql = "select u.* from a_order u  where 1=1 ";
        if(search.getName()!=null){
            sql+=" and u.name = ? ";
            params.add(search.getName());
        }

        if(search.getStatus()!=null){
            sql+=" and u.dealStatus = ? ";
            params.add(search.getStatus());
        }

        sql+=" order by u.createDate desc";
        findPageList(Map.class,sql,page,params.toArray());
        return page;
    }

    public Order getOrder(String curStudentId) {
        return sql("select * from a_order where studentId = ?").one(Order.class,curStudentId);
    }

    public void dealOrder(Order order) {
        sql("update a_order set dealStatus = ?,dealTime = now(),dealContent=? where id = ?").update(new Object[]{order.isDealStatus(),order.getDealContent(),order.getId()});
    }
}
